<extend name="Public/base" />
<block name="content">	
<script src="__STATIC__/aui-artDialog-9fd667e/dist/dialog.js"></script>
<script src="__STATIC__/aui-artDialog-9fd667e/dist/dialog-plus.js"></script>
<script src="__JS__/underscore.js"></script>
<link rel="stylesheet" href="__STATIC__/aui-artDialog-9fd667e/css/ui-dialog.css">							
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{:U('Index/index')}" title="首页" class="tip-bottom"><i class="icon-home"></i> 首页</a> 
			<a href="#" class="current">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<br/>
		<button class="btn btn-info" id="add">新 增</button>
		<button class="btn btn-success ajax-post " target-form="ids" url="{:U('setGoodsStatus?model=status&status=1')}">上 架</button>
		<button class="btn btn-warning ajax-post" target-form="ids" url="{:U('setGoodsStatus?model=status&status=2')}">下 架</button>
		<button class="btn btn-success ajax-post " target-form="ids" url="{:U('delPromotion')}">删除促销</button>
		<button class="btn btn-warning update_time">修改促销时间</button>
		<button class="confirm btn btn-danger ajax-post" url="{:U('setGoodsStatus?model=status&status=-1')}" target-form="ids">删 除</button>
	</div>
	<div class="container-fluid search-form">
			<form class="m-filter" autocomplete="off">
				<div class="clearfix">
					<a class="pull-left btn btn-success btn-filter-show" id="j-filter-show"><span class="icon-chevron-down"></span></a>
				</div>
				
				<div class="filter-box" id="j-filter-box">
					<!-- 基础信息 -->
					<div class="filter-base filter-group">
						<a class="title"><span class="icon-list"></span> 基础信息</a>
						
						<span class="control-group">
							<select class="form-control" style="width: 180px;" name="merchant_id" id="merchant_id" onchange="change_shop_list(this.value,'{:U('ServiceApi/getShopList')}')">
								<option value=0>选择商户</option>
								<volist name="merchant_list" id="vo">
									<option value='{$vo.merchant_id}'>{$vo.merchant_name|strip_tags}</option>
								</volist>
							</select>
						</span>
						<span class="control-group">
							<select class="form-control" style="width: 150px;" name="shop_id" id="shop_id" onchange="change_goods_category_pid(this.value,'{:U('ServiceApi/getGoodsCategoryPid')}')">
								<option value=0>选择店铺</option>
								<volist name="shop_list" id="vo">
									<option value='{$vo.shop_id}'>{$vo.shop_name|strip_tags}</option>
								</volist>
							</select>
						</span>
						<span class="control-group">
							<select class="form-control" style="width: 150px;" name="goods_category_pid" id="goods_category_pid" onchange="change_goods_category_id(this.value,'{:U('ServiceApi/getGoodsCategoryId')}')">
								<option value=0>选择一级品类</option>
								<volist name="category_list" id="vo">
									<option value='{$vo.goods_category_id}'>{$vo.goods_category_name|strip_tags}</option>
								</volist>
							</select>
						</span>
						<span class="control-group">
							<select class="form-control" style="width: 150px;" name="goods_category_id" id="goods_category_id">
								<option value=0>选择二级品类</option>
								<volist name="goods_category_list" id="vo">
									<option value='{$vo.goods_category_id}'>{$vo.goods_category_name|strip_tags}</option>
								</volist>
							</select>
						</span>
					</div>
					<!-- /基础信息 -->

					<!-- 基础信息 -->
					<div class="filter-base filter-group">
						<a class="title"><span class="icon-list"></span> 其他信息</a>
						<span class="control-group">
							<select class="form-control" style="width: 180px;" name="member_id" id="member_id">
								<option value=0>选择创建人</option>
								<volist name="member_list" id="vo">
									<option value='{$vo.uid}'>{$vo.member_name|strip_tags}</option>
								</volist>
							</select>
						</span>
						<span class="control-group">
							<select class="form-control" style="width: 150px;" name="status" id="status">
								<option value='-1'>选择商品状态</option>
								<option value='0' <if condition="(int)I('status') == 0">selected</if>>未上架</option>
								<option value='1' <if condition="(int)I('status') == 1">selected</if>>上架</option>
								<option value='2' <if condition="(int)I('status') == 2">selected</if>>下架</option>
							</select>
						</span>
						<span class="control-group">
							<select class="form-control" style="width: 150px;" name="goods_type" id="goods_type">
								<option value='-1'>选择商品类型</option>
								<option value='0' <if condition="(int)I('goods_type') == 0">selected</if>>正常销售</option>
								<option value='1' <if condition="(int)I('goods_type') == 1">selected</if>>促销</option>
								<option value='2' <if condition="(int)I('goods_type') == 2">selected</if>>团购</option>
							</select>
						</span>
						<span class="control-group">
							<select class="form-control" style="width: 150px;" name="position" id="position">
								<option value='-1'>推荐位置</option>
								<option value='0' <if condition="(int)I('position','-1') == 0">selected</if>>未选位置</option>
								<notempty name="position">
									<volist name="position" id="vo">
										<option value='{$key}' <if condition="(int)I('position') == $key">selected</if>>{$vo}</option>
									</volist>
								</notempty>
								
							</select>
						</span>
						
					</div>
				
					<!--  商品名称 -->
					<div class="filter-input filter-group clearfix">
						<a class="title"><span class="icon-globe"></span> 商品名称</a>
					  	<div class="control-group pull-left">
					    	<div class="controls">
								<input type="text" name="goods_name" value="{:strip_tags(I('goods_name'))}" placeholder="商品名称" class="search-input" maxlength="50" >
					    	</div>
					  	</div>
					</div>
					<!-- /商品名称  -->
				
					<div class="clearfix btn-group">
						<a class="btn btn-success btn pull-left" id="j-filter-hide" style="margin-left:15px;"><span class="icon-chevron-up"></span></a>
						<button type="button" id="search_button" url="{:U('ShopGoods/index')}" class="btn btn-primary btn pull-left"><span class="icon-search"></span></button>
					</div>	
				</div>		
			</form>
		</div>
		
	<div class="container-fluid">		
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-content ">
					<notempty name="_list">
						<form id="export-form" method="post" action="" autocomplete="off">
							<table class="table table-bordered table-striped with-check">
								<thead>
									<tr>
										<th width="5%"><input type="checkbox" /></th>
										<th width="5%" nowrap="nowrap">序号</th>
										<th width="21%">商品名</th>
										<th width="7%">商城价</th>
										<th width="5%">定金</th>
										<th width="6%">库存</th>
										<th width="7%">类型</th>
										<th width="7%">状态</th>
										<th width="7%">创建人</th>
										<th width="15%">创建时间</th>
										<th width="15%">操作</th>
									</tr>
								</thead>
								<tbody>
									<volist name="_list" id="vo">
										<tr>
											<td class="taskStatus"><input type="checkbox" value="{$vo.goods_id}" name="ids[]" class="ids"/></td>
											<td class="taskStatus">{$i}</td>
											
											<td class="taskStatus" align="left">{$vo.goods_name|htmlspecialchars|msubstr=###,0,20}</td>
											<td class="taskStatus">{$vo.shop_price|htmlspecialchars}</td>
											<td class="taskStatus">{$vo.goods_deposit|htmlspecialchars}</td>
											<td class="taskStatus">{$vo.goods_stock|htmlspecialchars}</td>
											<td class="taskStatus">{$vo.goods_type|get_goods_type_title}</td>
											<td class="taskStatus">{$vo.status_text|htmlspecialchars}</td>
											<td class="taskStatus">{$vo.member_id|getUserName=###}</td>
											<td class="taskStatus">{$vo.create_time|time_format=###}</td>
											<td class="taskStatus">
												<switch name="vo.status">
												<case value="0">
													<a class="confirm ajax-get" title="上架" href="{:U('setGoodsStatus?model=status&status=1&ids='.$vo['goods_id'])}"><i class="icon-edit"></i> 上架</a>
												</case>
												<case value="1">
													<a class="confirm ajax-get" title="下架" href="{:U('setGoodsStatus?model=status&status=2&ids='.$vo['goods_id'])}"><i class="icon-edit"></i> 下架</a>
												</case>
												<case value="2">
													<a class="confirm ajax-get" title="上架" href="{:U('setGoodsStatus?model=status&status=1&ids='.$vo['goods_id'])}"><i class="icon-edit"></i> 上架</a>
												</case>
												</switch>
												<a href="{:U('editSale?goods_id='.$vo['goods_id'])}"><i class="icon-edit"></i> 促销</a>
												<a href="{:U('editGroup?id='.$vo['goods_id'])}"><i class="icon-edit"></i> 团购</a>
												<a href="{:U('edit?goods_id='.$vo['goods_id'])}"><i class="icon-edit"></i> 编辑</a>
												<a href="{:U('setGoodsStatus?model=status&ids='.$vo['goods_id'].'&status=-1')}" class="ajax-get confirm"><i class="icon-remove"></i> 删除</a>
											</td>
										</tr>
									</volist>
								</tbody>
							</table>
							<div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers" id="DataTables_Table_0_paginate">
								{$_page}
							</div>
						</form>
					<else/>
						<center>暂无内容</center>
					</notempty>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/template" id="promotion_time_content">
	<div>
		<div class="controls">
			<input style="width:180px" readonly="readonly" 
		type="text" name="promotion_start_time_update" placeholder="促销开始时间" 
		class="search-input datepicker" maxlength="50" />	
		</div>	
		<div class="controls">
			<input style="width:180px" readonly="readonly" 
		type="text" name="promotion_end_time_update" placeholder="促销结束时间" 
		class="search-input datepicker" maxlength="50" />	
		</div>	
	</div>	
</script>
<script type="text/javascript">
$(function (){
	
	$('.update_time').click(function(){
		var ids =[]; 
    	$('input[name="ids[]"]:checked').each(function(){ 
    		ids.push($(this).val()); 
    	}); 

    	if(0 == ids.length){
    		alert('请选择要操作的数据');
    		return false;
    	}
    	
		var d = dialog({
		    title: '批量编辑促销时间',
		    content: $('#promotion_time_content').html(),
		    okValue: '确定',
		    ok: function () {
		    	//cur_time = '{$Think.NOW_TIME|time_format=###}';
		    	start = $('input[name=promotion_start_time_update]').val();
		    	end = $('input[name=promotion_end_time_update]').val();
		    	
		    	if('' == start){
		    		alert('开始时间不能为空');
		    		return false;
		    	}
		    	
		    	if('' == end){
		    		alert('结束时间不能为空');
		    		return false;
		    	}
		    	
		    	//验证开始时间是都大于当前时间
		    	/*if(0 != compare_time(cur_time,end)){
		    		alert('开始时间必须大于当前时间');
		    		return false;
		    	}*/
		    	
		    	//验证结束时间是否大于开始时间
		    	if(1 != compare_time(start,end)){
		    		//alert('开始时间必须小于结束时间');
		    		//return false;
		    	}
		    	//锁定登录按钮
				$('button').attr('disabled',true);
				$.post("{$post_url}", {promotion_start_time:start,promotion_end_time:end,ids:ids}, call_back, "json");
				return false;
		    },
		    cancelValue: '取消',
		    cancel: function () {}
		});
		d.show();
		
		$(".controls").find(".datepicker").datetimepicker({
	        format: 'yyyy-mm-dd hh:ii:ss',
	        autoclose: true,
	        todayBtn: true
	    });
		
		
		/**
		 * @todo 接收登录返回值
		 * @author PHP@妖孽 <dino_ma@163.com>
		 */
		function call_back(data){
			if(data.status==1){
				tke_alert(data.info,'alert-success');
				setTimeout(function(){
					window.location.href = data.url;
				},1500);
			} else {
				$('button').attr('disabled',false);
				tke_alert(data.info,'alert-error');
			}
		}

	});
	
	
	function compare_time(beginTime,endTime) {
	    var beginTimes = beginTime.substring(0, 10).split('-');
	    var endTimes = endTime.substring(0, 10).split('-');
	    beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19);
	    endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19);
	    var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;
	    if (a < 0) {
	    	//endTime小
	    	return 0;
	    } else if (a > 0) {
	    	//endTime大
	    	return 1;
	    } else if (a == 0) {
	    	return 2;
	    }
	}
	
	
	//条件框
	$("#j-filter-hide").click(function(){
		$("#j-filter-box").fadeOut(300);
		$("#j-filter-show").fadeIn(300);
	});
	$("#j-filter-show").click(function(){
		$("#j-filter-box").fadeIn(300);
		$(this).fadeOut(300);
	});
	
	set_value("merchant_id",'{:(int)I('get.merchant_id')}');
	set_value("shop_id",'{:(int)I('get.shop_id','-1')}');
	set_value("goods_category_pid",'{:(int)I('get.goods_category_pid','-1')}');
	set_value("goods_category_id",'{:(int)I('get.goods_category_id','-1')}');
	set_value("member_id",'{:(int)I('get.member_id')}');
	set_value("status",'{:(int)I('get.status','-1')}');
	set_value("goods_recommend",'{:(int)I('get.goods_recommend','-1')}');
	set_value("goods_type",'{:(int)I('get.goods_type','-1')}');
	
	//新增跳转页面
	$('#add').click(function(){
		window.location.href="{:U('ShopGoods/add')}";
	});
});
//导航高亮
highlight_subnav("{:U('ShopGoods/index')}");
</script>
</block>